<?php
/**
 *
 * Created by IntelliJ IDEA.
 * User: XD
 * Date: 2017/8/18
 * Time: 16:18
 */
/*
 * 可以将多个连接到一起
 * */
echo "<h2>PHP is fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This", " string", " was", " made", " with multiple parameters.";
/*
 * PHP is fun!

Hello world!
I'm about to learn PHP!
This string was made with multiple parameters.
 * */

$txt1="Learn PHP";
$txt2="w3cschool.cc";
$cars=array("Volvo","BMW","Toyota");

echo $txt1;
echo "<br>";
echo "Study PHP at $txt2";
echo "My car is a {$cars[0]}";


/*
 * Learn PHP
Study PHP at w3cschool.ccMy car is a Volvo
 * */
print "<h2>PHP is fun!</h2>";
print "Hello world!<br>";
print "I'm about to learn PHP!";

/*
 * PHP is fun!

Hello world!
I'm about to learn PHP!
 * */

$txt1="Learn PHP";
$txt2="w3cschool.cc";
$cars=array("Volvo","BMW","Toyota");

print $txt1;
print "<br>";
print "Study PHP at $txt2";
print "My car is a {$cars[0]}";
/*
 * Learn PHP
Study PHP at w3cschool.ccMy car is a Volvo
 * */

/**
 * String（字符串）, Integer（整型）, Float（浮点型）,
 * Boolean（布尔型）, Array（数组）, Object（对象）,
 * NULL（空值）。
 */

$x = 5985;
var_dump($x);  //int(5985)
echo "<br>";
$x = -345; // 负数
var_dump($x);  //int(-345)
echo "<br>";
$x = 0x8C; // 十六进制数
var_dump($x);  //int(140)
echo "<br>";
$x = 047; // 八进制数
var_dump($x);  //int(39)

$x = 10.365;
var_dump($x);  //float(10.365)
echo "<br>";
$x = 2.4e3;
var_dump($x);     //float(2400)
echo "<br>";
$x = 8E-5;
var_dump($x);  //float(8.0E-5)

$cars=array("Volvo","BMW","Toyota");
var_dump($cars);   //array(3) { [0]=> string(5) "Volvo" [1]=> string(3) "BMW" [2]=> string(6) "Toyota" }

/**
 * 常量
 */
// 区分大小写的常量名
define("GREETING", "欢迎访问 php.cn");
echo GREETING; // 输出 "欢迎访问 php.cn"
echo '<br>';
echo greeting; // 输出 "greeting"

// 不区分大小写的常量名
define("GREETING", "欢迎访问 php.cn", true);
echo greeting;  // 输出 "欢迎访问 php.cn"

//全局的
define("GREETING", "欢迎访问 php.cn");

function myTest6() {
    echo GREETING;
}

myTest6();    // 输出 "欢迎访问 php.cn"


/**
 *  字符串
 * http://www.php.cn/php/php-string.html
 */

$txt1="Hello world!";
$txt2="What a nice day!";
//在上面的代码中，我们已经使用了两次并置运算符。这是由于我们需要在两个字符串之间插入一个空格。
echo $txt1 . " " . $txt2;  // 链接两个字符串  并置运算符 (.) 用于把两个字符串值连接起来。

echo strlen("Hello world!");   //strlen() 函数返回字符串的长度（字符数）。 12

//如果在字符串中找到匹配，该函数会返回第一个匹配的字符位置。如果未找到匹配，则返回 FALSE。
echo strpos("Hello world!","world");  //6
?>